home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / jrpacman.c < prev    next >
C/C++ Source or Header  |  2000-05-12  |  13KB  |  388 lines

  1. /***************************************************************************
  2.  
  3. Jr. Pac Man memory map (preliminary)
  4.  
  5. 0000-3fff ROM
  6. 4000-47ff Video RAM (also color RAM)
  7. 4800-4fff RAM
  8. 8000-dfff ROM
  9.  
  10. memory mapped ports:
  11.  
  12. read:
  13. 5000      IN0
  14. 5040      IN1
  15. 5080      DSW1
  16.  
  17. *
  18.  * IN0 (all bits are inverted)
  19.  * bit 7 : CREDIT
  20.  * bit 6 : COIN 2
  21.  * bit 5 : COIN 1
  22.  * bit 4 : RACK TEST
  23.  * bit 3 : DOWN player 1
  24.  * bit 2 : RIGHT player 1
  25.  * bit 1 : LEFT player 1
  26.  * bit 0 : UP player 1
  27.  *
  28. *
  29.  * IN1 (all bits are inverted)
  30.  * bit 7 : TABLE or UPRIGHT cabinet select (1 = UPRIGHT)
  31.  * bit 6 : START 2
  32.  * bit 5 : START 1
  33.  * bit 4 : TEST SWITCH
  34.  * bit 3 : DOWN player 2 (TABLE only)
  35.  * bit 2 : RIGHT player 2 (TABLE only)
  36.  * bit 1 : LEFT player 2 (TABLE only)
  37.  * bit 0 : UP player 2 (TABLE only)
  38.  *
  39. *
  40.  * DSW1 (all bits are inverted)
  41.  * bit 7 :  ?
  42.  * bit 6 :  difficulty level
  43.  *                       1 = Normal  0 = Harder
  44.  * bit 5 :\ bonus pac at xx000 pts
  45.  * bit 4 :/ 00 = 10000  01 = 15000  10 = 20000  11 = 30000
  46.  * bit 3 :\ nr of lives
  47.  * bit 2 :/ 00 = 1  01 = 2  10 = 3  11 = 5
  48.  * bit 1 :\ play mode
  49.  * bit 0 :/ 00 = free play   01 = 1 coin 1 credit
  50.  *          10 = 1 coin 2 credits   11 = 2 coins 1 credit
  51.  *
  52.  
  53. write:
  54. 4ff2-4ffd 6 pairs of two bytes:
  55.           the first byte contains the sprite image number (bits 2-7), Y flip (bit 0),
  56.           X flip (bit 1); the second byte the color
  57. 5000      interrupt enable
  58. 5001      sound enable
  59. 5002      unused
  60. 5003      flip screen
  61. 5004      unused
  62. 5005      unused
  63. 5006      unused
  64. 5007      coin counter
  65. 5040-5044 sound voice 1 accumulator (nibbles) (used by the sound hardware only)
  66. 5045      sound voice 1 waveform (nibble)
  67. 5046-5049 sound voice 2 accumulator (nibbles) (used by the sound hardware only)
  68. 504a      sound voice 2 waveform (nibble)
  69. 504b-504e sound voice 3 accumulator (nibbles) (used by the sound hardware only)
  70. 504f      sound voice 3 waveform (nibble)
  71. 5050-5054 sound voice 1 frequency (nibbles)
  72. 5055      sound voice 1 volume (nibble)
  73. 5056-5059 sound voice 2 frequency (nibbles)
  74. 505a      sound voice 2 volume (nibble)
  75. 505b-505e sound voice 3 frequency (nibbles)
  76. 505f      sound voice 3 volume (nibble)
  77. 5062-506d Sprite coordinates, x/y pairs for 6 sprites
  78. 5070      palette bank
  79. 5071      colortable bank
  80. 5073      background priority over sprites
  81. 5074      char gfx bank
  82. 5075      sprite gfx bank
  83. 5080      scroll
  84. 50c0      Watchdog reset
  85.  
  86. I/O ports:
  87. OUT on port $0 sets the interrupt vector
  88.  
  89.  
  90. ***************************************************************************/
  91.  
  92. #include "driver.h"
  93. #include "vidhrdw/generic.h"
  94.  
  95.  
  96. void jrpacman_init_machine(void);
  97. int jrpacman_interrupt(void);
  98.  
  99. extern unsigned char *jrpacman_scroll,*jrpacman_bgpriority;
  100. extern unsigned char *jrpacman_charbank,*jrpacman_spritebank;
  101. extern unsigned char *jrpacman_palettebank,*jrpacman_colortablebank;
  102. void jrpacman_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom);
  103. int jrpacman_vh_start(void);
  104. void jrpacman_vh_stop(void);
  105. WRITE_HANDLER( jrpacman_videoram_w );
  106. WRITE_HANDLER( jrpacman_palettebank_w );
  107. WRITE_HANDLER( jrpacman_colortablebank_w );
  108. WRITE_HANDLER( jrpacman_charbank_w );
  109. WRITE_HANDLER( jrpacman_flipscreen_w );
  110. void jrpacman_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  111.  
  112. extern unsigned char *pengo_soundregs;
  113. WRITE_HANDLER( pengo_sound_enable_w );
  114. WRITE_HANDLER( pengo_sound_w );
  115.  
  116.  
  117.  
  118. static struct MemoryReadAddress readmem[] =
  119. {
  120.     { 0x0000, 0x3fff, MRA_ROM },
  121.     { 0x4000, 0x4fff, MRA_RAM },    /* including video and color RAM */
  122.     { 0x5000, 0x503f, input_port_0_r },    /* IN0 */
  123.     { 0x5040, 0x507f, input_port_1_r },    /* IN1 */
  124.     { 0x5080, 0x50bf, input_port_2_r },    /* DSW1 */
  125.     { 0x8000, 0xdfff, MRA_ROM },
  126.     { -1 }    /* end of table */
  127. };
  128.  
  129. static struct MemoryWriteAddress writemem[] =
  130. {
  131.     { 0x0000, 0x3fff, MWA_ROM },
  132.     { 0x4000, 0x47ff, jrpacman_videoram_w, &videoram, &videoram_size },
  133.     { 0x4800, 0x4fef, MWA_RAM },
  134.     { 0x4ff0, 0x4fff, MWA_RAM, &spriteram, &spriteram_size },
  135.     { 0x5000, 0x5000, interrupt_enable_w },
  136.     { 0x5001, 0x5001, pengo_sound_enable_w },
  137.     { 0x5003, 0x5003, jrpacman_flipscreen_w },
  138.     { 0x5040, 0x505f, pengo_sound_w, &pengo_soundregs },
  139.     { 0x5060, 0x506f, MWA_RAM, &spriteram_2 },
  140.     { 0x5070, 0x5070, jrpacman_palettebank_w, &jrpacman_palettebank },
  141.     { 0x5071, 0x5071, jrpacman_colortablebank_w, &jrpacman_colortablebank },
  142.     { 0x5073, 0x5073, MWA_RAM, &jrpacman_bgpriority },
  143.     { 0x5074, 0x5074, jrpacman_charbank_w, &jrpacman_charbank },
  144.     { 0x5075, 0x5075, MWA_RAM, &jrpacman_spritebank },
  145.     { 0x5080, 0x5080, MWA_RAM, &jrpacman_scroll },
  146.     { 0x50c0, 0x50c0, MWA_NOP },
  147.     { 0x8000, 0xdfff, MWA_ROM },
  148.     { -1 }    /* end of table */
  149. };
  150.  
  151.  
  152.  
  153. static struct IOWritePort writeport[] =
  154. {
  155.     { 0, 0, interrupt_vector_w },
  156.     { -1 }    /* end of table */
  157. };
  158.  
  159.  
  160. INPUT_PORTS_START( jrpacman )
  161.     PORT_START    /* IN0 */
  162.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_4WAY )
  163.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_4WAY )
  164.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_4WAY )
  165.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_4WAY )
  166.     PORT_BITX(    0x10, 0x10, IPT_DIPSWITCH_NAME | IPF_CHEAT, "Rack Test", KEYCODE_F1, IP_JOY_NONE )
  167.     PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
  168.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  169.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN1 )
  170.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN2 )
  171.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN3 )
  172.  
  173.     PORT_START    /* IN1 */
  174.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_4WAY | IPF_COCKTAIL )
  175.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_4WAY | IPF_COCKTAIL )
  176.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_4WAY | IPF_COCKTAIL )
  177.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_4WAY | IPF_COCKTAIL )
  178.     PORT_SERVICE( 0x10, IP_ACTIVE_LOW )
  179.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START1 )
  180.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START2 )
  181.     PORT_DIPNAME( 0x80, 0x80, DEF_STR( Cabinet ) )
  182.     PORT_DIPSETTING(    0x80, DEF_STR( Upright ) )
  183.     PORT_DIPSETTING(    0x00, DEF_STR( Cocktail ) )
  184.  
  185.     PORT_START    /* DSW0 */
  186.     PORT_DIPNAME( 0x03, 0x01, DEF_STR( Coinage ) )
  187.     PORT_DIPSETTING(    0x03, DEF_STR( 2C_1C ) )
  188.     PORT_DIPSETTING(    0x01, DEF_STR( 1C_1C ) )
  189.     PORT_DIPSETTING(    0x02, DEF_STR( 1C_2C ) )
  190.     PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
  191.     PORT_DIPNAME( 0x0c, 0x08, DEF_STR( Lives ) )
  192.     PORT_DIPSETTING(    0x00, "1" )
  193.     PORT_DIPSETTING(    0x04, "2" )
  194.     PORT_DIPSETTING(    0x08, "3" )
  195.     PORT_DIPSETTING(    0x0c, "5" )
  196.     PORT_DIPNAME( 0x30, 0x00, DEF_STR( Bonus_Life ) )
  197.     PORT_DIPSETTING(    0x00, "10000" )
  198.     PORT_DIPSETTING(    0x10, "15000" )
  199.     PORT_DIPSETTING(    0x20, "20000" )
  200.     PORT_DIPSETTING(    0x30, "30000" )
  201.     PORT_DIPNAME( 0x40, 0x40, DEF_STR( Difficulty ) )
  202.     PORT_DIPSETTING(    0x40, "Normal" )
  203.     PORT_DIPSETTING(    0x00, "Hard" )
  204.     PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
  205.     PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
  206.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  207.  
  208.     PORT_START    /* FAKE */
  209.     /* This fake input port is used to get the status of the fire button */
  210.     /* and activate the speedup cheat if it is. */
  211.     PORT_BITX(    0x01, 0x00, IPT_DIPSWITCH_NAME | IPF_CHEAT, "Speedup Cheat", KEYCODE_LCONTROL, JOYCODE_1_BUTTON1 )
  212.     PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
  213.     PORT_DIPSETTING(    0x01, DEF_STR( On ) )
  214. INPUT_PORTS_END
  215.  
  216.  
  217. static struct GfxLayout charlayout =
  218. {
  219.     8,8,
  220.     512,    /* 512 characters */
  221.     2,        /* 2 bits per pixel */
  222.     { 0, 4 },    /* the two bitplanes for 4 pixels are packed into one byte */
  223.     { 8*8+0, 8*8+1, 8*8+2, 8*8+3, 0, 1, 2, 3 },    /* bits are packed in groups of four */
  224.     { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
  225.     16*8    /* every char takes 16 bytes */
  226. };
  227. static struct GfxLayout spritelayout =
  228. {
  229.     16,16,    /* 16*16 sprites */
  230.     128,    /* 128 sprites */
  231.     2,        /* 2 bits per pixel */
  232.     { 0, 4 },    /* the two bitplanes for 4 pixels are packed into one byte */
  233.     { 8*8, 8*8+1, 8*8+2, 8*8+3, 16*8+0, 16*8+1, 16*8+2, 16*8+3,
  234.             24*8+0, 24*8+1, 24*8+2, 24*8+3, 0, 1, 2, 3 },
  235.     { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
  236.             32*8, 33*8, 34*8, 35*8, 36*8, 37*8, 38*8, 39*8 },
  237.     64*8    /* every sprite takes 64 bytes */
  238. };
  239.  
  240.  
  241.  
  242. static struct GfxDecodeInfo gfxdecodeinfo[] =
  243. {
  244.     { REGION_GFX1, 0, &charlayout,      0, 128 },
  245.     { REGION_GFX2, 0, &spritelayout,    0, 128 },
  246.     { -1 } /* end of array */
  247. };
  248.  
  249.  
  250.  
  251. static struct namco_interface namco_interface =
  252. {
  253.     3072000/32,    /* sample rate */
  254.     3,            /* number of voices */
  255.     100,        /* playback volume */
  256.     REGION_SOUND1    /* memory region */
  257. };
  258.  
  259.  
  260.  
  261. static struct MachineDriver machine_driver_jrpacman =
  262. {
  263.     /* basic machine hardware */
  264.     {
  265.         {
  266.             CPU_Z80,
  267.             18432000/6,    /* 3.072 Mhz */
  268.             readmem,writemem,0,writeport,
  269.             jrpacman_interrupt,1
  270.         }
  271.     },
  272.     60, 2500,    /* frames per second, vblank duration */
  273.     1,    /* single CPU, no need for interleaving */
  274.     jrpacman_init_machine,
  275.  
  276.     /* video hardware */
  277.     36*8, 28*8, { 0*8, 36*8-1, 0*8, 28*8-1 },
  278.     gfxdecodeinfo,
  279.     32,128*4,
  280.     jrpacman_vh_convert_color_prom,
  281.  
  282.     VIDEO_TYPE_RASTER,
  283.     0,
  284.     jrpacman_vh_start,
  285.     jrpacman_vh_stop,
  286.     jrpacman_vh_screenrefresh,
  287.  
  288.     /* sound hardware */
  289.     0,0,0,0,
  290.     {
  291.         {
  292.             SOUND_NAMCO,
  293.             &namco_interface
  294.         }
  295.     }
  296. };
  297.  
  298.  
  299.  
  300. /***************************************************************************
  301.  
  302.   Game driver(s)
  303.  
  304. ***************************************************************************/
  305.  
  306. ROM_START( jrpacman )
  307.     ROM_REGION( 0x10000, REGION_CPU1 )    /* 64k for code */
  308.     ROM_LOAD( "jrp8d.bin",    0x0000, 0x2000, 0xe3fa972e )
  309.     ROM_LOAD( "jrp8e.bin",    0x2000, 0x2000, 0xec889e94 )
  310.     ROM_LOAD( "jrp8h.bin",    0x8000, 0x2000, 0x35f1fc6e )
  311.     ROM_LOAD( "jrp8j.bin",    0xa000, 0x2000, 0x9737099e )
  312.     ROM_LOAD( "jrp8k.bin",    0xc000, 0x2000, 0x5252dd97 )
  313.  
  314.     ROM_REGION( 0x2000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  315.     ROM_LOAD( "jrp2c.bin",    0x0000, 0x2000, 0x0527ff9b )
  316.  
  317.     ROM_REGION( 0x2000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  318.     ROM_LOAD( "jrp2e.bin",    0x0000, 0x2000, 0x73477193 )
  319.  
  320.     ROM_REGION( 0x0300, REGION_PROMS )
  321.     ROM_LOAD( "jrprom.9e",    0x0000, 0x0100, 0x029d35c4 ) /* palette low bits */
  322.     ROM_LOAD( "jrprom.9f",    0x0100, 0x0100, 0xeee34a79 ) /* palette high bits */
  323.     ROM_LOAD( "jrprom.9p",    0x0200, 0x0100, 0x9f6ea9d8 ) /* color lookup table */
  324.  
  325.     ROM_REGION( 0x0200, REGION_SOUND1 )    /* sound prom */
  326.     ROM_LOAD( "jrprom.7p",    0x0000, 0x0100, 0xa9cc86bf )
  327.     ROM_LOAD( "jrprom.5s",    0x0100, 0x0100, 0x77245b66 )    /* timing - not used */
  328. ROM_END
  329.  
  330.  
  331.  
  332. static void init_jrpacman(void)
  333. {
  334.     /* The encryption PALs garble bits 0, 2 and 7 of the ROMs. The encryption */
  335.     /* scheme is complex (basically it's a state machine) and can only be */
  336.     /* faithfully emulated at run time. To avoid the performance hit that would */
  337.     /* cause, here we have a table of the values which must be XORed with */
  338.     /* each memory region to obtain the decrypted bytes. */
  339.     /* Decryption table provided by David Caldwell (david@indigita.com) */
  340.     /* For an accurate reproduction of the encryption, see jrcrypt.c */
  341.     struct {
  342.         int count;
  343.         int value;
  344.     } table[] =
  345.     {
  346.         { 0x00C1, 0x00 },{ 0x0002, 0x80 },{ 0x0004, 0x00 },{ 0x0006, 0x80 },
  347.         { 0x0003, 0x00 },{ 0x0002, 0x80 },{ 0x0009, 0x00 },{ 0x0004, 0x80 },
  348.         { 0x9968, 0x00 },{ 0x0001, 0x80 },{ 0x0002, 0x00 },{ 0x0001, 0x80 },
  349.         { 0x0009, 0x00 },{ 0x0002, 0x80 },{ 0x0009, 0x00 },{ 0x0001, 0x80 },
  350.         { 0x00AF, 0x00 },{ 0x000E, 0x04 },{ 0x0002, 0x00 },{ 0x0004, 0x04 },
  351.         { 0x001E, 0x00 },{ 0x0001, 0x80 },{ 0x0002, 0x00 },{ 0x0001, 0x80 },
  352.         { 0x0002, 0x00 },{ 0x0002, 0x80 },{ 0x0009, 0x00 },{ 0x0002, 0x80 },
  353.         { 0x0009, 0x00 },{ 0x0002, 0x80 },{ 0x0083, 0x00 },{ 0x0001, 0x04 },
  354.         { 0x0001, 0x01 },{ 0x0001, 0x00 },{ 0x0002, 0x05 },{ 0x0001, 0x00 },
  355.         { 0x0003, 0x04 },{ 0x0003, 0x01 },{ 0x0002, 0x00 },{ 0x0001, 0x04 },
  356.         { 0x0003, 0x01 },{ 0x0003, 0x00 },{ 0x0003, 0x04 },{ 0x0001, 0x01 },
  357.         { 0x002E, 0x00 },{ 0x0078, 0x01 },{ 0x0001, 0x04 },{ 0x0001, 0x05 },
  358.         { 0x0001, 0x00 },{ 0x0001, 0x01 },{ 0x0001, 0x04 },{ 0x0002, 0x00 },
  359.         { 0x0001, 0x01 },{ 0x0001, 0x04 },{ 0x0002, 0x00 },{ 0x0001, 0x01 },
  360.         { 0x0001, 0x04 },{ 0x0002, 0x00 },{ 0x0001, 0x01 },{ 0x0001, 0x04 },
  361.         { 0x0001, 0x05 },{ 0x0001, 0x00 },{ 0x0001, 0x01 },{ 0x0001, 0x04 },
  362.         { 0x0002, 0x00 },{ 0x0001, 0x01 },{ 0x0001, 0x04 },{ 0x0002, 0x00 },
  363.         { 0x0001, 0x01 },{ 0x0001, 0x04 },{ 0x0001, 0x05 },{ 0x0001, 0x00 },
  364.         { 0x01B0, 0x01 },{ 0x0001, 0x00 },{ 0x0002, 0x01 },{ 0x00AD, 0x00 },
  365.         { 0x0031, 0x01 },{ 0x005C, 0x00 },{ 0x0005, 0x01 },{ 0x604E, 0x00 },
  366.         { 0,0 }
  367.     };
  368.     int i,j,A;
  369.     unsigned char *RAM = memory_region(REGION_CPU1);
  370.  
  371.  
  372.     A = 0;
  373.     i = 0;
  374.     while (table[i].count)
  375.     {
  376.         for (j = 0;j < table[i].count;j++)
  377.         {
  378.             RAM[A] ^= table[i].value;
  379.             A++;
  380.         }
  381.         i++;
  382.     }
  383. }
  384.  
  385.  
  386.  
  387. GAME( 1983, jrpacman, 0, jrpacman, jrpacman, jrpacman, ROT90, "Bally Midway", "Jr. Pac-Man" )
  388.